<?php
require 'Admin/Controller/Controller.php ';
require 'Admin/Model/UserModel.php';
class UserController extends Controller{
	function __Construct(){
		parent::__Construct();
		$this->model = new UserModel();
	}
	function index(){ 
		
		$data = $this->model->getList();
		$this->assign('list',$data);
		$this->display();  
 
	}

	function logout()
{
	session_start(); 
	if(!isset($_SESSION['user'])){
		/*echo'<a href="admin/view/user/login.html">无权限，请登录</a>';*/
		  redirect('admin/view/user/login.html', '无权限，请登录！');  
		exit();
	}
	if(isset($_SESSION['user'])){
		unset($_SESSION['user']);
		//session_destroy();
	redirect('admin/view/user/login.html', '注销成功！');
	}	
	
}



function Login()
	{

$result=$this->mod->login();
var_dump($result);
//$redirect=$this->model->redirect($url, $msg);
if($result){
   /* $_SESSION['user'] = $result;*/
	  
	  redirect('admin.php?c=User&m=index', '登录成功!');
	  
	  	
  }else{
	redirect('index.php?c=index&m=index', '用户名或密码错误！请重新登录！');	  
	   
  } 
	}





	function form(){
		require'admin/view/user/form.php';
	}
	function add(){
		$data = $_POST;
		$result = $this->model->add($data);
		if($result){
			redirect('admin.php?c=User&m=index', '成功!');
			/*echo '添加成功 <a href="admin.php?c=user&m=index">如果没有跳转，请点这里跳转</a>';
   			header("refresh:3;url='admin.php?c=user&m=index'");*/
		}
		else{
			redirect('admin.php?c=user&m=userform', '失败!');
			/*echo "添加失败！<br/>";
  			echo "<a href='admin.php?c=user&m=userform'>返回</a>";*/
		}

	}
	function del(){
		$id = $_GET['id'];
		$result = $this->model->del($id);
		if($result){
			echo '删除成功 <a href="admin.php?c=user&m=index">如果没有跳转，请点这里跳转</a>';
   			header("refresh:3;url='admin.php?c=user&m=index'");
		}
		else{
			echo "删除失败！<br/>";
  			echo "<a href='admin.php?c=user&m=index'>返回</a>";
		}
	}
	function dels(){}
	function mod(){
		$id = $_GET['id'];
		$result = $this->model->getOneByID($id);
	  //var_dump($result);
		require'admin/view/user/mod.php';
		/*$this->assign('one',$result);
		$this->display();*/
	}
	function update(){
		$data = $_POST;
		$result = $this->model->update($data);
		if($result){
			echo '更新成功 <a href="admin.php?c=user&m=index">如果没有跳转，请点这里跳转</a>';
   			header("refresh:3;url='admin.php?c=user&m=index'");
		}
		else{
			echo "更新失败！<br/>";
  			echo "<a href='admin.php?c=user&m=usermod&id=".$data['id']."'>返回</a>";
		}
	}
	function search(){
		$key=$_POST['key'];
		$model=new UserModel();
		$data=$model->search($key);
		var_dump($data);
		require 'admin/view/user/search.php';

	}function display()
    {
        $model = new UserModel();
        $data = $model->getList();
        require('admin/view/cartoon/list.php');
    }
}
?>
